//
//  DeviceDetailListViewController.swift
//  XSQWiFi
//
//  Created by XinPengLee on 2025/5/8.
//

import UIKit

class DeviceDetailListViewController: UIViewController {
    var deviceName: String?

    @IBOutlet weak var gradiesView: UIView!

    @IBOutlet weak var tableView: UITableView!
    
    @IBOutlet weak var searchTextF: UITextField!
    @IBOutlet weak var searchView: UIView!
    @IBOutlet weak var searchButton: UIButton!
    
    @IBOutlet weak var previousButton: UIButton!
    @IBOutlet weak var loopButton: UIButton!
    @IBOutlet weak var nextButton: UIButton!
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor().colorConversionHex(Color_Value: "#F5F5F5")
        createUI()
    }

    func createUI() {
        navigation.bar.backgroundColor = UIColor.clear
        navigation.bar.isTranslucent = false
        navigation.bar.tintColor = UIColor.darkText
        navigation.bar.statusBarStyle = .darkContent
        navigation.bar.titleTextAttributes = [
            .foregroundColor: UIColor.darkText
        ]
        navigation.item.title = deviceName ?? "设备名称"
        let uploadItem = UIBarButtonItem(image: UIImage(named: "upload"), style: .plain, target: self, action: #selector(uploadClick))
        let settingItem = UIBarButtonItem(image: UIImage(named: "setting"), style: .plain, target: self, action: #selector(settingClick))
        navigation.item.rightBarButtonItems = [settingItem,uploadItem]
        
        gradiesView.setupGradientBackground(startColor: UIColor().colorConversionHex(Color_Value: "#90BAF7"), endColor: UIColor().colorConversionHex(Color_Value: "#F5F5F5"), startPoint: CGPoint(x: 0.5, y: 0), endPoint: CGPoint(x: 0.5, y: 1))

        
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(UINib.init(nibName: "DeviceMaterialTableViewCell", bundle: nil), forCellReuseIdentifier: "DeviceMaterialTableViewCell")
        
        searchView.layer.cornerRadius = 17
        searchView.layer.borderWidth = 2
        searchView.layer.borderColor = UIColor().colorConversionHex(Color_Value: "#0558F4").cgColor
        
        searchButton.layer.cornerRadius = 12
        searchButton.layer.masksToBounds = true
        
        
        previousButton.layer.cornerRadius = 24
        previousButton.layer.shadowOffset = CGSize.init(width: 0, height: 0)
        previousButton.layer.shadowColor = UIColor().colorConversionHex(Color_Value: "#000000").cgColor
        previousButton.layer.shadowOpacity = 0.15;//阴影透明度，默认0
        previousButton.layer.shadowRadius = 8;//阴影半径，默认3
        loopButton.layer.cornerRadius = 24
        loopButton.layer.cornerRadius = 24
        loopButton.layer.shadowOffset = CGSize.init(width: 0, height: 0)
        loopButton.layer.shadowColor = UIColor().colorConversionHex(Color_Value: "#000000").cgColor
        loopButton.layer.shadowOpacity = 0.15;//阴影透明度，默认0
        loopButton.layer.shadowRadius = 8;//阴影半径，默认3
        nextButton.layer.cornerRadius = 24
        nextButton.layer.cornerRadius = 24
        nextButton.layer.shadowOffset = CGSize.init(width: 0, height: 0)
        nextButton.layer.shadowColor = UIColor().colorConversionHex(Color_Value: "#000000").cgColor
        nextButton.layer.shadowOpacity = 0.15;//阴影透明度，默认0
        nextButton.layer.shadowRadius = 8;//阴影半径，默认3
    }
    @IBAction func searchButtonClick(_ sender: UIButton) {
        XPLog(message: "点击搜索")
    }
    @objc func uploadClick() {
        XPLog(message: "上传")
    }
    @objc func settingClick() {
        XPLog(message: "设置")
    }
}

extension DeviceDetailListViewController: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 20
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "DeviceMaterialTableViewCell") as! DeviceMaterialTableViewCell
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 112
    }
    
    
    
    
}
